package com.remedios.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.remedios.service.MailSendLogService;
import com.ruoyi.system.api.domain.MailSendLog;
import com.ruoyi.system.api.vo.MailSendLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @
 */
@RestController
@RequestMapping("mailServer")
public class MailController extends BaseController {
    @Autowired
    private MailSendLogService mailSendLogService;

    /**
     * 查询邮件日志列表
     */
    @RequiresPermissions("system:mailLog:list")
    @GetMapping("/list")
    public TableDataInfo list(MailSendLog mailSendLog)
    {
        startPage();
        List<MailSendLogVo> list = mailSendLogService.selectMailSendLogList(mailSendLog);
        return getDataTable(list);
    }

//    /**
//     * 导出邮件日志列表
//     */
//    @RequiresPermissions("system:mailLog:export")
//    @Log(title = "邮件日志", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, MailSendLog mailSendLog)
//    {
//        List<MailSendLogVo> list = mailSendLogService.selectMailSendLogList(mailSendLog);
//        ExcelUtil<MailSendLog> util = new ExcelUtil<MailSendLog>(MailSendLog.class);
//        util.exportExcel(response, list, "邮件日志数据");
//    }

    /**
     * 获取邮件日志详细信息
     */
    @RequiresPermissions("system:mailLog:query")
    @GetMapping(value = "/{msgId}")
    public AjaxResult getInfo(@PathVariable("msgId") String msgIds)
    {
        return AjaxResult.success(mailSendLogService.selectMailSendLogByMsgId(msgIds));
    }

    /**
     * 新增邮件日志
     */
    @RequiresPermissions("system:mailLog:add")
       @Log(title = "邮件日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MailSendLog mailSendLog)
    {
        return toAjax(mailSendLogService.insertMailSendLog(mailSendLog));
    }

    /**
     * 修改邮件日志
     */
    @RequiresPermissions("system:mailLog:edit")
       @Log(title = "邮件日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MailSendLog mailSendLog)
    {
        return toAjax(mailSendLogService.updateMailSendLog(mailSendLog));
    }

    /**
     * 重发邮件
     */
    @RequiresPermissions("system:mailLog:resend")
       @Log(title = "邮件日志", businessType = BusinessType.OTHER)
    @PostMapping("reSend")
    public AjaxResult reSend(@RequestBody MailSendLog mailSendLog)
    {
        return toAjax(mailSendLogService.reSend(mailSendLog));
    }

    /**
     * 删除邮件日志
     */
    @RequiresPermissions("system:mailLog:remove")
     @Log(title = "邮件日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{msgIds}")
    public AjaxResult remove(@PathVariable String[] msgIds)
    {
        return toAjax(mailSendLogService.deleteMailSendLogByMsgIds(msgIds));
    }
}
